﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using ServiceOTO.Entity;
using System.Data;

namespace ServiceOTO.Dataaccess
{
    public class KHACHHANG_DATAACCESS
    {
        private static string sp_Name = "KH_INSERT";
        public static Int32 InsertGetID(string ACTION, KHACHHANG_ENTITY KH)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            try
            {

                com.Connection = csdl.CheckConnect();                
                if (KH != null)
                {
                    com.Parameters.AddWithValue("@MAKH", KH.MAKH);
                    com.Parameters.AddWithValue("@TENKH", KH.TENKH);
                    com.Parameters.AddWithValue("@DIENTHOAI", KH.DIENTHOAI);
                    com.Parameters.AddWithValue("@DIACHI", KH.DIACHI);
                    com.Parameters.AddWithValue("@EMAIL", KH.EMAIL);
                    com.Parameters.AddWithValue("@MASOTHUE", KH.MASOTHUE);

                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                return Convert.ToInt32(com.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
    }
}